/*==============================================================*/
/* DBMS name:      Microsoft SQL Server 2005                    */
/* Created on:     3/12/2011 8:25:11 PM                         */
/*==============================================================*/


if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('BoMon') and o.name = 'FK_BOMON_ASSOCIATI_KHOA')
alter table BoMon
   drop constraint FK_BOMON_ASSOCIATI_KHOA
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('CanBo') and o.name = 'FK_CANBO_GENERALIZ_NGUOIDUN')
alter table CanBo
   drop constraint FK_CANBO_GENERALIZ_NGUOIDUN
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('CanBoGiangDay') and o.name = 'FK_CANBOGIA_ASSOCIATI_BOMON')
alter table CanBoGiangDay
   drop constraint FK_CANBOGIA_ASSOCIATI_BOMON
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('CanBoGiangDay') and o.name = 'FK_CANBOGIA_GENERALIZ_CANBO')
alter table CanBoGiangDay
   drop constraint FK_CANBOGIA_GENERALIZ_CANBO
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('CanBoGiangDay') and o.name = 'FK_CANBOGIA_GIU_CHUCVU')
alter table CanBoGiangDay
   drop constraint FK_CANBOGIA_GIU_CHUCVU
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ChuDeGiangDay') and o.name = 'FK_CHUDEGIA_ASSOCIATI_DECUONGC')
alter table ChuDeGiangDay
   drop constraint FK_CHUDEGIA_ASSOCIATI_DECUONGC
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('DangKiHoc') and o.name = 'FK_DANGKIHO_DANGKIHOC_LOPHOCPH')
alter table DangKiHoc
   drop constraint FK_DANGKIHO_DANGKIHOC_LOPHOCPH
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('DangKiHoc') and o.name = 'FK_DANGKIHO_DANGKIHOC_SINHVIEN')
alter table DangKiHoc
   drop constraint FK_DANGKIHO_DANGKIHOC_SINHVIEN
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('DeCuongChiTiet') and o.name = 'FK_DECUONGC_ASSOCIATI_HOCPHAN')
alter table DeCuongChiTiet
   drop constraint FK_DECUONGC_ASSOCIATI_HOCPHAN
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('DeCuongChiTiet') and o.name = 'FK_DECUONGC_ASSOCIATI_NGANHHOC')
alter table DeCuongChiTiet
   drop constraint FK_DECUONGC_ASSOCIATI_NGANHHOC
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('LopHocPhan') and o.name = 'FK_LOPHOCPH_ASSOCIATI_CANBOGIA')
alter table LopHocPhan
   drop constraint FK_LOPHOCPH_ASSOCIATI_CANBOGIA
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('LopHocPhan') and o.name = 'FK_LOPHOCPH_ASSOCIATI_HOCPHAN')
alter table LopHocPhan
   drop constraint FK_LOPHOCPH_ASSOCIATI_HOCPHAN
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('NganhHoc') and o.name = 'FK_NGANHHOC_ASSOCIATI_KHOA')
alter table NganhHoc
   drop constraint FK_NGANHHOC_ASSOCIATI_KHOA
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('NguoiDung') and o.name = 'FK_NGUOIDUN_CO_QUYEN')
alter table NguoiDung
   drop constraint FK_NGUOIDUN_CO_QUYEN
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('NguoiQuanTri') and o.name = 'FK_NGUOIQUA_GENERALIZ_CANBO')
alter table NguoiQuanTri
   drop constraint FK_NGUOIQUA_GENERALIZ_CANBO
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('NhatKi') and o.name = 'FK_NHATKI_ASSOCIATI_LOPHOCPH')
alter table NhatKi
   drop constraint FK_NHATKI_ASSOCIATI_LOPHOCPH
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('NhatKiChiTiet') and o.name = 'FK_NHATKICH_ASSOCIATI_NHATKI')
alter table NhatKiChiTiet
   drop constraint FK_NHATKICH_ASSOCIATI_NHATKI
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('NhatKiChiTiet') and o.name = 'FK_NHATKICH_GHI_XAC_N_SINHVIEN')
alter table NhatKiChiTiet
   drop constraint FK_NHATKICH_GHI_XAC_N_SINHVIEN
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('NhomThucHanh') and o.name = 'FK_NHOMTHUC_ASSOCIATI_LOPHOCPH')
alter table NhomThucHanh
   drop constraint FK_NHOMTHUC_ASSOCIATI_LOPHOCPH
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('NhomThucHanh') and o.name = 'FK_NHOMTHUC_ASSOCIATI_LOAINHOM')
alter table NhomThucHanh
   drop constraint FK_NHOMTHUC_ASSOCIATI_LOAINHOM
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('SinhVien') and o.name = 'FK_SINHVIEN_GENERALIZ_NGUOIDUN')
alter table SinhVien
   drop constraint FK_SINHVIEN_GENERALIZ_NGUOIDUN
go

if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('ThoiKhoaBieu') and o.name = 'FK_THOIKHOA_ASSOCIATI_LOPHOCPH')
alter table ThoiKhoaBieu
   drop constraint FK_THOIKHOA_ASSOCIATI_LOPHOCPH
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('BoMon')
            and   name  = 'ASSOCIATION2_FK'
            and   indid > 0
            and   indid < 255)
   drop index BoMon.ASSOCIATION2_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('BoMon')
            and   type = 'U')
   drop table BoMon
go

if exists (select 1
            from  sysobjects
           where  id = object_id('CanBo')
            and   type = 'U')
   drop table CanBo
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('CanBoGiangDay')
            and   name  = 'GIU_FK'
            and   indid > 0
            and   indid < 255)
   drop index CanBoGiangDay.GIU_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('CanBoGiangDay')
            and   name  = 'ASSOCIATION13_FK'
            and   indid > 0
            and   indid < 255)
   drop index CanBoGiangDay.ASSOCIATION13_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('CanBoGiangDay')
            and   type = 'U')
   drop table CanBoGiangDay
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ChuDeGiangDay')
            and   name  = 'ASSOCIATION15_FK'
            and   indid > 0
            and   indid < 255)
   drop index ChuDeGiangDay.ASSOCIATION15_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ChuDeGiangDay')
            and   type = 'U')
   drop table ChuDeGiangDay
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ChucVu')
            and   type = 'U')
   drop table ChucVu
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('DangKiHoc')
            and   name  = 'DANGKIHOC_FK2'
            and   indid > 0
            and   indid < 255)
   drop index DangKiHoc.DANGKIHOC_FK2
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('DangKiHoc')
            and   name  = 'DANGKIHOC_FK'
            and   indid > 0
            and   indid < 255)
   drop index DangKiHoc.DANGKIHOC_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('DangKiHoc')
            and   type = 'U')
   drop table DangKiHoc
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('DeCuongChiTiet')
            and   name  = 'ASSOCIATION6_FK2'
            and   indid > 0
            and   indid < 255)
   drop index DeCuongChiTiet.ASSOCIATION6_FK2
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('DeCuongChiTiet')
            and   name  = 'ASSOCIATION6_FK'
            and   indid > 0
            and   indid < 255)
   drop index DeCuongChiTiet.ASSOCIATION6_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('DeCuongChiTiet')
            and   type = 'U')
   drop table DeCuongChiTiet
go

if exists (select 1
            from  sysobjects
           where  id = object_id('HocPhan')
            and   type = 'U')
   drop table HocPhan
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Khoa')
            and   type = 'U')
   drop table Khoa
go

if exists (select 1
            from  sysobjects
           where  id = object_id('LoaiNhomTH')
            and   type = 'U')
   drop table LoaiNhomTH
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('LopHocPhan')
            and   name  = 'ASSOCIATION12_FK'
            and   indid > 0
            and   indid < 255)
   drop index LopHocPhan.ASSOCIATION12_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('LopHocPhan')
            and   name  = 'ASSOCIATION8_FK'
            and   indid > 0
            and   indid < 255)
   drop index LopHocPhan.ASSOCIATION8_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('LopHocPhan')
            and   name  = 'ASSOCIATION3_FK'
            and   indid > 0
            and   indid < 255)
   drop index LopHocPhan.ASSOCIATION3_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('LopHocPhan')
            and   type = 'U')
   drop table LopHocPhan
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('NganhHoc')
            and   name  = 'ASSOCIATION1_FK'
            and   indid > 0
            and   indid < 255)
   drop index NganhHoc.ASSOCIATION1_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('NganhHoc')
            and   type = 'U')
   drop table NganhHoc
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('NguoiDung')
            and   name  = 'CO_FK'
            and   indid > 0
            and   indid < 255)
   drop index NguoiDung.CO_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('NguoiDung')
            and   type = 'U')
   drop table NguoiDung
go

if exists (select 1
            from  sysobjects
           where  id = object_id('NguoiQuanTri')
            and   type = 'U')
   drop table NguoiQuanTri
go

if exists (select 1
            from  sysobjects
           where  id = object_id('NhatKi')
            and   type = 'U')
   drop table NhatKi
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('NhatKiChiTiet')
            and   name  = 'GHI_XAC_NHAN_FK'
            and   indid > 0
            and   indid < 255)
   drop index NhatKiChiTiet.GHI_XAC_NHAN_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('NhatKiChiTiet')
            and   name  = 'ASSOCIATION9_FK'
            and   indid > 0
            and   indid < 255)
   drop index NhatKiChiTiet.ASSOCIATION9_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('NhatKiChiTiet')
            and   type = 'U')
   drop table NhatKiChiTiet
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('NhomThucHanh')
            and   name  = 'ASSOCIATION21_FK'
            and   indid > 0
            and   indid < 255)
   drop index NhomThucHanh.ASSOCIATION21_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('NhomThucHanh')
            and   name  = 'ASSOCIATION14_FK'
            and   indid > 0
            and   indid < 255)
   drop index NhomThucHanh.ASSOCIATION14_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('NhomThucHanh')
            and   type = 'U')
   drop table NhomThucHanh
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Quyen')
            and   type = 'U')
   drop table Quyen
go

if exists (select 1
            from  sysobjects
           where  id = object_id('SinhVien')
            and   type = 'U')
   drop table SinhVien
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ThoiGianGhiNhatKi')
            and   type = 'U')
   drop table ThoiGianGhiNhatKi
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ThoiKhoaBieu')
            and   name  = 'ASSOCIATION4_FK'
            and   indid > 0
            and   indid < 255)
   drop index ThoiKhoaBieu.ASSOCIATION4_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ThoiKhoaBieu')
            and   type = 'U')
   drop table ThoiKhoaBieu
go

/*==============================================================*/
/* Table: BoMon                                                 */
/*==============================================================*/
create table BoMon (
   mabm                 varchar(254)         not null,
   makhoa               varchar(254)         not null,
   tenbm                varchar(254)         null,
   constraint PK_BOMON primary key nonclustered (mabm)
)
go

/*==============================================================*/
/* Index: ASSOCIATION2_FK                                       */
/*==============================================================*/
create index ASSOCIATION2_FK on BoMon (
makhoa ASC
)
go

/*==============================================================*/
/* Table: CanBo                                                 */
/*==============================================================*/
create table CanBo (
   maso                 varchar(254)         not null,
   holot                varchar(254)         null,
   ten                  varchar(254)         null,
   ngaysinh             DateTime             null,
   phai                 varchar(254)         null,
   diachi               varchar(254)         null,
   email                varchar(254)         null,
   sodt                 varchar(254)         null,
   constraint PK_CANBO primary key (maso)
)
go

/*==============================================================*/
/* Table: CanBoGiangDay                                         */
/*==============================================================*/
create table CanBoGiangDay (
   maso                 varchar(254)         not null,
   mabm                 varchar(254)         not null,
   macv                 varchar(254)         null,
   hocvi                varchar(254)         null,
   constraint PK_CANBOGIANGDAY primary key (maso)
)
go

/*==============================================================*/
/* Index: ASSOCIATION13_FK                                      */
/*==============================================================*/
create index ASSOCIATION13_FK on CanBoGiangDay (
mabm ASC
)
go

/*==============================================================*/
/* Index: GIU_FK                                                */
/*==============================================================*/
create index GIU_FK on CanBoGiangDay (
macv ASC
)
go

/*==============================================================*/
/* Table: ChuDeGiangDay                                         */
/*==============================================================*/
create table ChuDeGiangDay (
   manganh              varchar(254)         not null,
   mahp                 varchar(254)         not null,
   Stt                  int                  not null,
   noidung              varchar(254)         null,
   sotiet               int                  null,
   constraint PK_CHUDEGIANGDAY primary key nonclustered (manganh, mahp, Stt)
)
go

/*==============================================================*/
/* Index: ASSOCIATION15_FK                                      */
/*==============================================================*/
create index ASSOCIATION15_FK on ChuDeGiangDay (
manganh ASC,
mahp ASC
)
go

/*==============================================================*/
/* Table: ChucVu                                                */
/*==============================================================*/
create table ChucVu (
   macv                 varchar(254)         not null,
   tencv                varchar(254)         null,
   constraint PK_CHUCVU primary key nonclustered (macv)
)
go

/*==============================================================*/
/* Table: DangKiHoc                                             */
/*==============================================================*/
create table DangKiHoc (
   maso                 varchar(254)         not null,
   malophp              varchar(254)         not null,
   constraint PK_DANGKIHOC primary key (maso, malophp)
)
go

/*==============================================================*/
/* Index: DANGKIHOC_FK                                          */
/*==============================================================*/
create index DANGKIHOC_FK on DangKiHoc (
maso ASC
)
go

/*==============================================================*/
/* Index: DANGKIHOC_FK2                                         */
/*==============================================================*/
create index DANGKIHOC_FK2 on DangKiHoc (
malophp ASC
)
go

/*==============================================================*/
/* Table: DeCuongChiTiet                                        */
/*==============================================================*/
create table DeCuongChiTiet (
   manganh              varchar(254)         not null,
   mahp                 varchar(254)         not null,
   sotietbatbuoc        int                  null,
   sotiettuchon         int                  null,
   sotietlithuyet       int                  null,
   sotietthuchanh       int                  null,
   matuchon             varchar(254)         null,
   hptienquyet          varchar(254)         null,
   muctieu              int                  null,
   ppgiangday           int                  null,
   danhgiahp            int                  null,
   constraint PK_DECUONGCHITIET primary key (manganh, mahp)
)
go

/*==============================================================*/
/* Index: ASSOCIATION6_FK                                       */
/*==============================================================*/
create index ASSOCIATION6_FK on DeCuongChiTiet (
manganh ASC
)
go

/*==============================================================*/
/* Index: ASSOCIATION6_FK2                                      */
/*==============================================================*/
create index ASSOCIATION6_FK2 on DeCuongChiTiet (
mahp ASC
)
go

/*==============================================================*/
/* Table: HocPhan                                               */
/*==============================================================*/
create table HocPhan (
   mahp                 varchar(254)         not null,
   tenhp                varchar(254)         null,
   sotc                 int                  null,
   constraint PK_HOCPHAN primary key nonclustered (mahp)
)
go

/*==============================================================*/
/* Table: Khoa                                                  */
/*==============================================================*/
create table Khoa (
   makhoa               varchar(254)         not null,
   tenkhoa              varchar(254)         null,
   constraint PK_KHOA primary key nonclustered (makhoa)
)
go

/*==============================================================*/
/* Table: LoaiNhomTH                                            */
/*==============================================================*/
create table LoaiNhomTH (
   maloai               varchar(254)         not null,
   thoigianapdung       DateTime             not null,
   mota                 varchar(254)         null,
   heso                 float                null,
   constraint PK_LOAINHOMTH primary key nonclustered (maloai, thoigianapdung)
)
go

/*==============================================================*/
/* Table: LopHocPhan                                            */
/*==============================================================*/
create table LopHocPhan (
   malophp              varchar(254)         not null,
   mahp                 varchar(254)         not null,
   maso                 varchar(254)         not null,
   hocki                varchar(254)         not null,
   nienkhoa             varchar(254)         not null,
   siso                 int                  null,
   constraint PK_LOPHOCPHAN primary key nonclustered (malophp)
)
go

/*==============================================================*/
/* Index: ASSOCIATION3_FK                                       */
/*==============================================================*/
create index ASSOCIATION3_FK on LopHocPhan (
mahp ASC
)
go

/*==============================================================*/
/* Index: ASSOCIATION8_FK                                       */
/*==============================================================*/
create index ASSOCIATION8_FK on LopHocPhan (

)
go

/*==============================================================*/
/* Index: ASSOCIATION12_FK                                      */
/*==============================================================*/
create index ASSOCIATION12_FK on LopHocPhan (
maso ASC
)
go

/*==============================================================*/
/* Table: NganhHoc                                              */
/*==============================================================*/
create table NganhHoc (
   manganh              varchar(254)         not null,
   makhoa               varchar(254)         not null,
   tennganh             varchar(254)         null,
   constraint PK_NGANHHOC primary key nonclustered (manganh)
)
go

/*==============================================================*/
/* Index: ASSOCIATION1_FK                                       */
/*==============================================================*/
create index ASSOCIATION1_FK on NganhHoc (
makhoa ASC
)
go

/*==============================================================*/
/* Table: NguoiDung                                             */
/*==============================================================*/
create table NguoiDung (
   maso                 varchar(254)         not null,
   maquyen              varchar(254)         not null,
   matkhau              varchar(254)         null,
   constraint PK_NGUOIDUNG primary key nonclustered (maso)
)
go

/*==============================================================*/
/* Index: CO_FK                                                 */
/*==============================================================*/
create index CO_FK on NguoiDung (
maquyen ASC
)
go

/*==============================================================*/
/* Table: NguoiQuanTri                                          */
/*==============================================================*/
create table NguoiQuanTri (
   maSo                 varchar(254)         not null,
   nghiepVu             varchar(254)         null,
   constraint PK_NGUOIQUANTRI primary key (maSo)
)
go

/*==============================================================*/
/* Table: NhatKi                                                */
/*==============================================================*/
create table NhatKi (
   malophp              varchar(254)         not null,
   tongsotiet           int                  null,
   tietdungkehoach      int                  null,
   tietdaybu            int                  null,
   tietkhongday         int                  null,
   tongket              varchar(254)         null,
   nhanxetcuabm         varchar(254)         null,
   daidienbm            int                  null,
   nhanxetcuadv         int                  null,
   daidiendv            int                  null,
   constraint PK_NHATKI primary key (malophp)
)
go

/*==============================================================*/
/* Table: NhatKiChiTiet                                         */
/*==============================================================*/
create table NhatKiChiTiet (
   malophp              varchar(254)         not null,
   tuan                 int                  not null,
   thu                  int                  not null,
   maso                 varchar(254)         not null,
   ngay                 DateTime             null,
   sotiet               int                  null,
   hinhthucday          varchar(254)         null,
   noidung              varchar(254)         null,
   sosvhiendien         int                  null,
   xacnhancuasv         int                  null,
   daidiensv            varchar(254)         null,
   constraint PK_NHATKICHITIET primary key nonclustered (malophp, tuan, thu)
)
go

/*==============================================================*/
/* Index: ASSOCIATION9_FK                                       */
/*==============================================================*/
create index ASSOCIATION9_FK on NhatKiChiTiet (
malophp ASC
)
go

/*==============================================================*/
/* Index: GHI_XAC_NHAN_FK                                       */
/*==============================================================*/
create index GHI_XAC_NHAN_FK on NhatKiChiTiet (
maso ASC
)
go

/*==============================================================*/
/* Table: NhomThucHanh                                          */
/*==============================================================*/
create table NhomThucHanh (
   Stt                  int                  not null,
   malophp              varchar(254)         not null,
   maloai               varchar(254)         not null,
   thoigianapdung       DateTime             not null,
   siso                 int                  null,
   constraint PK_NHOMTHUCHANH primary key nonclustered (Stt)
)
go

/*==============================================================*/
/* Index: ASSOCIATION14_FK                                      */
/*==============================================================*/
create index ASSOCIATION14_FK on NhomThucHanh (
malophp ASC
)
go

/*==============================================================*/
/* Index: ASSOCIATION21_FK                                      */
/*==============================================================*/
create index ASSOCIATION21_FK on NhomThucHanh (
maloai ASC,
thoigianapdung ASC
)
go

/*==============================================================*/
/* Table: Quyen                                                 */
/*==============================================================*/
create table Quyen (
   maquyen              varchar(254)         not null,
   diengiai             varchar(254)         null,
   constraint PK_QUYEN primary key nonclustered (maquyen)
)
go

/*==============================================================*/
/* Table: SinhVien                                              */
/*==============================================================*/
create table SinhVien (
   maso                 varchar(254)         not null,
   holot                varchar(254)         null,
   ten                  varchar(254)         null,
   ngaysinh             DateTime             null,
   phai                 varchar(254)         null,
   diachi               varchar(254)         null,
   email                varchar(254)         null,
   sodt                 varchar(254)         null,
   constraint PK_SINHVIEN primary key (maso)
)
go

/*==============================================================*/
/* Table: ThoiGianGhiNhatKi                                     */
/*==============================================================*/
create table ThoiGianGhiNhatKi (
   hocki                int                  not null,
   nienkhoa             varchar(254)         not null,
   sttmuc               int                  not null,
   diengiai             varchar(254)         null,
   tungay               datetime             null,
   denngay              datetime             null,
   constraint PK_THOIGIANGHINHATKI primary key nonclustered (hocki, nienkhoa, sttmuc)
)
go

/*==============================================================*/
/* Table: ThoiKhoaBieu                                          */
/*==============================================================*/
create table ThoiKhoaBieu (
   malophp              varchar(254)         not null,
   thu                  int                  not null,
   tietbd               int                  not null,
   sotiet               int                  null,
   phong                varchar(254)         null,
   tuanhoc              varchar(254)         null,
   constraint PK_THOIKHOABIEU primary key nonclustered (malophp, thu, tietbd)
)
go

/*==============================================================*/
/* Index: ASSOCIATION4_FK                                       */
/*==============================================================*/
create index ASSOCIATION4_FK on ThoiKhoaBieu (
malophp ASC
)
go

alter table BoMon
   add constraint FK_BOMON_ASSOCIATI_KHOA foreign key (makhoa)
      references Khoa (makhoa)
go

alter table CanBo
   add constraint FK_CANBO_GENERALIZ_NGUOIDUN foreign key (maso)
      references NguoiDung (maso)
go

alter table CanBoGiangDay
   add constraint FK_CANBOGIA_ASSOCIATI_BOMON foreign key (mabm)
      references BoMon (mabm)
go

alter table CanBoGiangDay
   add constraint FK_CANBOGIA_GENERALIZ_CANBO foreign key (maso)
      references CanBo (maso)
go

alter table CanBoGiangDay
   add constraint FK_CANBOGIA_GIU_CHUCVU foreign key (macv)
      references ChucVu (macv)
go

alter table ChuDeGiangDay
   add constraint FK_CHUDEGIA_ASSOCIATI_DECUONGC foreign key (manganh, mahp)
      references DeCuongChiTiet (manganh, mahp)
go

alter table DangKiHoc
   add constraint FK_DANGKIHO_DANGKIHOC_LOPHOCPH foreign key (malophp)
      references LopHocPhan (malophp)
go

alter table DangKiHoc
   add constraint FK_DANGKIHO_DANGKIHOC_SINHVIEN foreign key (maso)
      references SinhVien (maso)
go

alter table DeCuongChiTiet
   add constraint FK_DECUONGC_ASSOCIATI_HOCPHAN foreign key (mahp)
      references HocPhan (mahp)
go

alter table DeCuongChiTiet
   add constraint FK_DECUONGC_ASSOCIATI_NGANHHOC foreign key (manganh)
      references NganhHoc (manganh)
go

alter table LopHocPhan
   add constraint FK_LOPHOCPH_ASSOCIATI_CANBOGIA foreign key (maso)
      references CanBoGiangDay (maso)
go

alter table LopHocPhan
   add constraint FK_LOPHOCPH_ASSOCIATI_HOCPHAN foreign key (mahp)
      references HocPhan (mahp)
go

alter table NganhHoc
   add constraint FK_NGANHHOC_ASSOCIATI_KHOA foreign key (makhoa)
      references Khoa (makhoa)
go

alter table NguoiDung
   add constraint FK_NGUOIDUN_CO_QUYEN foreign key (maquyen)
      references Quyen (maquyen)
go

alter table NguoiQuanTri
   add constraint FK_NGUOIQUA_GENERALIZ_CANBO foreign key (maSo)
      references CanBo (maso)
go

alter table NhatKi
   add constraint FK_NHATKI_ASSOCIATI_LOPHOCPH foreign key (malophp)
      references LopHocPhan (malophp)
go

alter table NhatKiChiTiet
   add constraint FK_NHATKICH_ASSOCIATI_NHATKI foreign key (malophp)
      references NhatKi (malophp)
go

alter table NhatKiChiTiet
   add constraint FK_NHATKICH_GHI_XAC_N_SINHVIEN foreign key (maso)
      references SinhVien (maso)
go

alter table NhomThucHanh
   add constraint FK_NHOMTHUC_ASSOCIATI_LOPHOCPH foreign key (malophp)
      references LopHocPhan (malophp)
go

alter table NhomThucHanh
   add constraint FK_NHOMTHUC_ASSOCIATI_LOAINHOM foreign key (maloai, thoigianapdung)
      references LoaiNhomTH (maloai, thoigianapdung)
go

alter table SinhVien
   add constraint FK_SINHVIEN_GENERALIZ_NGUOIDUN foreign key (maso)
      references NguoiDung (maso)
go

alter table ThoiKhoaBieu
   add constraint FK_THOIKHOA_ASSOCIATI_LOPHOCPH foreign key (malophp)
      references LopHocPhan (malophp)
go

